package com.itheima.web.controller;

import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserManager userManager;

    @GetMapping("/manage/users")// 分页查询用户列表
    public ResponseEntity findUserInfoByPage(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                             @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize){
        return userManager.findUserInfoByPage(pageNum,pageSize);
    }

    @GetMapping("/manage/users/{userId}")// 用户详情
    public ResponseEntity findUserInfoByUserId(@PathVariable Long userId){
        return userManager.findUserInfoByUserId(userId);
    }

    @GetMapping("/manage/messages")// 动态分页查询
    public ResponseEntity findMovementVoByPage(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                               @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize,
                                               @RequestParam(required = false) Long uid,
                                               Integer state){
        return userManager.findMovementVoByPage(uid,state,pageNum,pageSize);
    }

    @GetMapping("/manage/messages/{publishId}")// 动态详情查询
    public ResponseEntity findMovementVoById(@PathVariable String publishId){
        return userManager.findMovementVoById(publishId);
    }

    @GetMapping("/manage/messages/comments")// 动态评论分页查询
    public ResponseEntity findCommentVoByPage(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                              @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize,
                                              @RequestParam(value = "messageID", required = false) String publishId){
        return userManager.findCommentVoByPage(pageNum,pageSize,publishId);
    }

    @GetMapping("/manage/videos")// 查询指定用户id分页视频
    public ResponseEntity findVideoVoByPage(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize,
                                            @RequestParam(value = "uid", required = false) Long userId){
        return userManager.findVideoVoByPage(pageNum,pageSize,userId);
    }

}
